import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		UPDATE: false,
		// URL: "http://192.168.10.100:8060/Wxweb/",//本地
		URL: "https://wmyq.hbyiquan.com:63300/Wxweb/",//生产环境
		TOKEN: '',
		USER_INFO: ''
	},
	mutations: {
		LOGIN(state, token) {
			uni.setStorage({
				key: 'TOKEN',
				data: token,
				success: (res) => {
					state.TOKEN = token
					// console.log(state.TOKEN);
				}
			})
		},
		SIGN_OUT(state) {
			uni.removeStorage({
				key: 'USER_INFO'
			});
			uni.removeStorage({
				key: 'TOKEN'
			})
			state.USER_INFO = ''
			state.TOKEN = ''
			// console.log("state.USER_INFO: " +JSON.stringify( state.USER_INFO));
		},
		TO_UPDATE(state, res) {
			state.UPDATE = res;
			// console.log('state.UPDATE'+state.UPDATE);
		},
		GET_USER_INFO(state) {
			uni.getStorage({
				key: 'USER_INFO',
				success: res => {
					state.USER_INFO = res.data;
					// console.log(JSON.stringify( res.data) );
				}
			});
		},
		GET_TOKEN(state) {
			uni.getStorage({
				key: 'TOKEN',
				success: res => {
					state.TOKEN = res.data;
					console.log(JSON.stringify( res.data) );
				}
			});
		},
		SHOW_LOGIN(state) {
			uni.showModal({
				content: '请先登录',
				success: res => {
					if (res.confirm) {
						uni.navigateTo({
							url: '../login/login'
						});
					}
				}
			});
		},
	}
})

export default store
